package org.jef.core.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.jef.core.jackson.PigJavaTimeModule;

/**
 * @version 1.0
 * @program: JsonUtils
 * @description:
 * @author: ChengZhi 0336
 * @create: 2024-08-05 19:25
 **/
public class JsonUtils {

	private static final ObjectMapper JSON = new ObjectMapper();

	static {
		JSON.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		JSON.configure(SerializationFeature.INDENT_OUTPUT, Boolean.TRUE);
		JSON.registerModule(new PigJavaTimeModule());
	}

	public static String toJson(Object obj) {
		try {
			return JSON.writeValueAsString(obj);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}

		return null;
	}
}
